package com.lcx.plugin.tool;

import com.google.common.base.CaseFormat;
import com.google.common.base.Converter;

/**
 * 驼峰-下划线互转工具类
 *
 * @author daxiong
 * @date 2023/6/16 上午8:54
 */
public class CaseFormatUtil {
    /**
     * 驼峰转下划线转换器
     */
    private final static Converter<String, String> CAMEL_TO_UNDERSCORE =
            CaseFormat.LOWER_CAMEL.converterTo(CaseFormat.LOWER_UNDERSCORE);

    /**
     * 下划线转驼峰转换器
     */
    private final static Converter<String, String> UNDERSCORE_TO_CAMEL =
            CaseFormat.LOWER_UNDERSCORE.converterTo(CaseFormat.LOWER_CAMEL);

    /**
     * 驼峰转下划线
     *
     * @param source
     * @return java.lang.String
     * @author daxiong
     * @date 2023/5/23 下午1:57
     */
    public static String camel2UnderScore(String source) {
        return CAMEL_TO_UNDERSCORE.convert(source);
    }

    /**
     * 下划线转驼峰
     *
     * @param source
     * @return java.lang.String
     * @author daxiong
     * @date 2023/5/23 下午1:58
     */
    public static String underScore2Camel(String source) {
        return UNDERSCORE_TO_CAMEL.convert(source);
    }
}
